package com.finer.service.impl;

import com.finer.entity.buy.BuyCompare;
import com.finer.dao.BuyCompareDao;
import com.finer.service.BuyCompareService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 采购比价表(BuyCompare)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:36
 */
@Service("buyCompareService")
public class BuyCompareServiceImpl implements BuyCompareService {
    @Resource
    private BuyCompareDao buyCompareDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BuyCompare queryById(Integer id) {
        return this.buyCompareDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param buyCompare 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<BuyCompare> queryByPage(BuyCompare buyCompare, PageRequest pageRequest) {
        long total = this.buyCompareDao.count(buyCompare);
        return new PageImpl<>(this.buyCompareDao.queryAllByLimit(buyCompare, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param buyCompare 实例对象
     * @return 实例对象
     */
    @Override
    public BuyCompare insert(BuyCompare buyCompare) {
        this.buyCompareDao.insert(buyCompare);
        return buyCompare;
    }

    /**
     * 修改数据
     *
     * @param buyCompare 实例对象
     * @return 实例对象
     */
    @Override
    public BuyCompare update(BuyCompare buyCompare) {
        this.buyCompareDao.update(buyCompare);
        return this.queryById(buyCompare.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.buyCompareDao.deleteById(id) > 0;
    }
}
